package cn.dengta.webapp.user.entity.activity;

import java.util.Date;

import cn.dengta.common.util.Common;
import cn.dengta.webapp.base.entity.TimeBasedEntity;
import cn.dengta.webapp.user.model.ChristmasTask;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.Cmp;

/**
 * 圣诞活动任务
 *
 * @author xy
 * @since 2022-12-14
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName("act_christmas_task")
public class ActChristmasTask extends TimeBasedEntity {

	private static final long serialVersionUID = 1L;

	/** 周期 */
	Date period;
	/** 用户id */
	Long userId;
	/** 任务：1=每日登录；2=兑换金币；3=搭讪；4=赠送圣诞礼物；5=收到圣诞礼物；6=充值 */
	ChristmasTask task;
	/** 奖品数量 */
	Integer prize;
	/** 状态：0=初始化；1=已完成；2=已领取 */
	Integer status;
	/** 任务对应的最大id;如：充值记录的最大id */
	Long maxTaskId;

	public static ActChristmasTask of(Date period, Long userId, ChristmasTask ta) {
		ActChristmasTask task = new ActChristmasTask();
		task.setPeriod(period);
		task.setUserId(userId);
		task.setTask(ta);
		task.setPrize(ta.getPrize());
		return task;
	}

	/** 是否已领取 */
	public boolean canReceive() {
		return Cmp.eq(this.status, 2);
	}

	public static final String PERIOD = "period";
	public static final String USER_ID = "user_id";
	public static final String TASK = "task";
	public static final String PRIZE = "prize";
	public static final String STATUS = "status";

	public static ChristmasTask ofTask(Integer task) {
		return Common.getEnum(ChristmasTask.values(), ChristmasTask::getCode, task);
	}

}
